//
//  YWTextFieldCell.m
//  maintain
//
//  Created by 烟雨云渊 on 16/8/9.
//  Copyright © 2016年 ewin. All rights reserved.
//

#import "YWTextFieldCell.h"
#import "Masonry.h"
#import "YWMacro.h"

@interface YWTextFieldCell()<UITextFieldDelegate>
/**  更换配件  **/
@property (nonatomic ,strong) UITextField * contentTextField;
@end

@implementation YWTextFieldCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUpSubviews];
    }
    
    return self;
}

- (void)setUpSubviews{
   
    [self.contentTextField mas_makeConstraints:^(MASConstraintMaker *make) {
       make.edges.equalTo(self.contentView).insets(UIEdgeInsetsMake(10, 10, 10, 10));
    }];
}

- (void)setTextFieldContent:(NSString *)textFieldContent{
    _textFieldContent = textFieldContent;
    self.contentTextField.text = textFieldContent;
}

- (void)setCanInput:(BOOL)canInput{
    _canInput = canInput;
    self.contentTextField.userInteractionEnabled = canInput ? YES : NO;
}

- (void)setTextFieldPlaceholder:(NSString *)textFieldPlaceholder{
    _textFieldPlaceholder = textFieldPlaceholder;
    self.contentTextField.placeholder = textFieldPlaceholder;
}

-(void)setTextFieldKeyboardType:(UIKeyboardType)textFieldKeyboardType{
    self.contentTextField.keyboardType = textFieldKeyboardType;
}

- (UITextField *)contentTextField{
    if (!_contentTextField) {
        UITextField * textField = [[UITextField alloc] init];
        textField.placeholder = @"如有，请输入配件名";
        textField.font = kContentFont;
        textField.delegate = self;
        [self.contentView addSubview:textField];
        _contentTextField = textField;
    }
    return _contentTextField;
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    NSString *changeParts = [textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    if ([self.delegate respondsToSelector:@selector(passTextFieldContent:cell:)]) {
        [self.delegate passTextFieldContent:changeParts cell:self];
    }
}
@end
